package cn.edu.neusoft.wuguangsheng.flowerimpression.fragment;


import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import cn.edu.neusoft.wuguangsheng.flowerimpression.R;
import cn.edu.neusoft.wuguangsheng.flowerimpression.activity.AddSheQuActivity;
import cn.edu.neusoft.wuguangsheng.flowerimpression.adapter.SheQuAdapter;
import cn.edu.neusoft.wuguangsheng.flowerimpression.bean.SheQuInfoBean;
import cn.edu.neusoft.wuguangsheng.flowerimpression.listener.ListListener;
import cn.edu.neusoft.wuguangsheng.flowerimpression.model.GetSheQuListModel;

/**
 * A simple {@link Fragment} subclass.
 */
public class SheQuFragment extends BaseFragment {
    TextView shequ_wyfb;
    RecyclerView shequ_rv;
boolean up = false;
    private List<SheQuInfoBean> items;
    TextView shequ_shuaxing;
    String userid;





    @Override
    void initView() {
        shequ_wyfb = (TextView)view.findViewById(R.id.shequ_wyfb);
        shequ_rv = (RecyclerView)view.findViewById(R.id.shequ_rv);
        shequ_shuaxing = (TextView)view.findViewById(R.id.shequ_shuaxing);
        userid = getid();

        GetSheQuListModel getSheQuListModel = new GetSheQuListModel();
        getSheQuListModel.getSheQuList(new ListListener<SheQuInfoBean>() {
            @Override
            public void onResponse(List<SheQuInfoBean> list) {
                LinearLayoutManager linearLayoutManager=new LinearLayoutManager(getContext());
                linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);

                shequ_rv.setLayoutManager(linearLayoutManager);
                items=list;
                SheQuAdapter sheQuAdapter=new SheQuAdapter(getContext(),items,R.layout.shequ_item,getid());
                shequ_rv.setAdapter(sheQuAdapter);
                shequ_rv.setItemAnimator(new DefaultItemAnimator());
            }

            @Override
            public void onFail(String msg) {

            }
        });

    }


    @Override
    void initEvent() {
        shequ_wyfb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(), AddSheQuActivity.class);
            startActivity(intent);
            }
        });
        shequ_shuaxing.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                initView();
                initEvent();
                initDate();
            }
        });

    }

    @Override
    void initDate() {

    }

    public SheQuFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        setLayout_file(R.layout.fragment_she_qu);
        return super.onCreateView(inflater,container,savedInstanceState);
    }

    @Override
    public void onPause() {
        super.onPause();
        up = true;
    }

    @Override
    public void onResume() {
        super.onResume();
        if (up) {
            initView();
            initEvent();
            initDate();
            up = false;
        }
    }

}
